package com.uzai.console.web.tb.tbtokenapi;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import com.uzai.console.annotation.SystemLogType;
import com.uzai.console.dto.tb.tborder.TbOrderApiDownLoadDto;
import com.uzai.console.dto.tb.tbtokenapi.*;
import com.uzai.console.enums.OperationTypeEnum;
import com.uzai.console.enums.SystemModelEnum;
import com.uzai.console.service.tb.tborder.TbOrderService;
import com.uzai.console.service.tb.tbtokenapi.TbTokenApiService;
import com.uzai.console.vo.tb.tbtokenapi.TbTokenApiAuthUrlVo;
import com.uzai.console.vo.tb.tbtokenapi.TbTokenApiInfoVo;
import com.uzai.console.vo.tb.tbtokenapi.TbTokenApiPageVo;
import com.uzai.console.web.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 产品
 * @author liuqi
 * @date 2021年08月16日 15:11
 */
@Api(value = "拉取订单淘宝联盟",tags = "淘宝|拉取订单淘宝联盟")
@ApiSort(9)
@RestController
public class TbTokenApiController extends BaseController {
    private Logger logger = LoggerFactory.getLogger(TbTokenApiController.class);

    @Autowired
    private TbTokenApiService tbTokenApiService;
    @Autowired
    private TbOrderService tbOrderService;

    @ApiOperation(value = "分页查询拉取订单淘宝联盟列表", notes = "分页查询拉取订单淘宝联盟列表", response = TbTokenApiPageVo.class)
    @ApiOperationSupport(order = 1)
    @PostMapping("/tbTokenApi/findTbTokenApiList")
    public Object findTbTokenApiList(@RequestBody TbTokenApiQuery tbTokenApiQuery){
        //查询拉取订单淘宝
        tbTokenApiQuery.setType(0);
        return tbTokenApiService.findTbTokenApiList(tbTokenApiQuery);
    }

    @SystemLogType(model = SystemModelEnum.TbTokenApi, type = OperationTypeEnum.ADD)
    @ApiOperation(value = "添加联盟账号", notes = "添加联盟账号", response = TbTokenApiAuthUrlVo.class)
    @ApiOperationSupport(order = 4)
    @PostMapping("/tbTokenApi/addToken")
    public Object addToken(){
        return tbTokenApiService.addTbTokenApi(getLoginInfo().getMerId());
    }

    @SystemLogType(model = SystemModelEnum.TbTokenApi, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "重新授权", notes = "重新授权", response = TbTokenApiAuthUrlVo.class)
    @ApiOperationSupport(order = 5)
    @PostMapping("/tbTokenApi/reauthorize")
    public Object reauthorize(){
        return tbTokenApiService.addTbTokenApi(getLoginInfo().getMerId());
    }

    @ApiOperation(value = "查询联盟详情", notes = "查询联盟详情", response = TbTokenApiInfoVo.class)
    @ApiOperationSupport(order = 6)
    @PostMapping("/tbTokenApi/findTbTokenApiInfo")
    public Object findTbTokenApiInfo(@RequestBody TbTokenApiIdDto tbTokenApiIdDto){
        return tbTokenApiService.findTbTokenApiInfo(tbTokenApiIdDto);
    }

    @SystemLogType(model = SystemModelEnum.TbTokenApi, type = OperationTypeEnum.DELETE)
    @ApiOperation(value = "删除", notes = "删除")
    @ApiOperationSupport(order = 9)
    @PostMapping("/tbTokenApi/deleteTbTokenApi")
    public Object deleteTbTokenApi(@RequestBody TbTokenApiIdDto tbTokenApiIdDto){
        tbTokenApiService.deleteTbTokenApi(tbTokenApiIdDto);
        return true;
    }

    @SystemLogType(model = SystemModelEnum.TbTokenApi, type = OperationTypeEnum.DOWNLOAD)
    @ApiOperation(value = "通过api手动下载淘宝订单", notes = "通过api手动下载淘宝订单")
    @ApiOperationSupport(order = 10)
    @PostMapping("/tbTokenApi/downloadOrderByApi")
    public Object downloadOrderByApi(@RequestBody TbOrderApiDownLoadDto tbOrderApiDownLoadDto){
        tbOrderService.downloadOrderApi(tbOrderApiDownLoadDto);
        return true;
    }
}
